//
//  ST_BTChangeAvatarAlertController.swift
//  btvideo
//
//  Created by mac on 2020/9/2.
//  Copyright © 2020 JarvanZhang. All rights reserved.
//

import UIKit
import SwifterSwift

class ST_BTChangeAvatarAlertController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        view.addSubview(root_view)
        root_view.snp.makeConstraints { (make) in
            make.width.equalTo(300)
            make.height.equalTo(439)
            make.centerX.equalToSuperview()
            make.centerY.equalToSuperview()
        }
        
        
        root_view.addSubview(cover_image_view)
        cover_image_view.snp.makeConstraints { (make) in
            make.size.equalTo(CGSize.init(width: 90, height: 90))
            make.top.equalToSuperview().offset(20)
            make.centerX.equalToSuperview()
        }
        
        
        root_view.addSubview(cover_tips_image_view)
        cover_tips_image_view.snp.makeConstraints { (make) in
            make.width.height.equalTo(26)
            make.bottom.right.equalTo(cover_image_view)
        }
        
        root_view.addSubview(titleLabel)
        titleLabel.snp.makeConstraints { (make) in
            make.height.equalTo(25)
            make.top.equalTo(cover_image_view.snp.bottom).offset(20)
            make.centerX.equalToSuperview()
        }
        
        root_view.addSubview(content_label)
        content_label.snp.makeConstraints { (make) in
            make.top.equalTo(titleLabel.snp.bottom).offset(6)
            make.centerX.equalToSuperview()
            make.left.equalToSuperview().offset(35)
            make.right.equalToSuperview().offset(-35)
        }
        
        
        
        
        root_view.addSubview(center_image_view)
        center_image_view.snp.makeConstraints { (make) in
            make.width.height.equalTo(60)
            make.centerX.equalToSuperview()
            make.top.equalTo(content_label.snp.bottom).offset(41)
        }
        
        root_view.addSubview(center_mistake_image_view)
        center_mistake_image_view.snp.makeConstraints { (make) in
            make.width.height.equalTo(16)
            make.centerX.equalTo(center_image_view)
            make.bottom.equalTo(center_image_view.snp.top).offset(-5)
        }
        
        root_view.addSubview(left_image_view)
        left_image_view.snp.makeConstraints { (make) in
            make.width.height.equalTo(center_image_view)
            make.right.equalTo(center_image_view.snp.left).offset(-30)
            make.top.equalTo(center_image_view)
        }
        
        root_view.addSubview(left_mistake_image_view)
        left_mistake_image_view.snp.makeConstraints { (make) in
            make.width.height.equalTo(16)
            make.centerX.equalTo(left_image_view)
            make.bottom.equalTo(left_image_view.snp.top).offset(-5)
        }
        
        root_view.addSubview(right_image_view)
        right_image_view.snp.makeConstraints { (make) in
            make.width.height.equalTo(center_image_view)
            make.left.equalTo(center_image_view.snp.right).offset(30)
            make.top.equalTo(center_image_view)
        }
        
        root_view.addSubview(right_mistake_image_view)
        right_mistake_image_view.snp.makeConstraints { (make) in
            make.width.height.equalTo(16)
            make.centerX.equalTo(right_image_view)
            make.bottom.equalTo(right_image_view.snp.top).offset(-5)
        }
        
        
        root_view.addSubview(center_label)
        center_label.snp.makeConstraints { (make) in
            make.centerX.equalToSuperview()
            make.top.equalTo(right_image_view.snp.bottom).offset(8)
        }
        
        root_view.addSubview(left_label)
        left_label.snp.makeConstraints { (make) in
            make.centerX.equalTo(left_image_view)
            make.top.equalTo(right_image_view.snp.bottom).offset(8)
        }
        
        root_view.addSubview(right_label)
        right_label.snp.makeConstraints { (make) in
            make.centerX.equalTo(right_image_view)
            make.top.equalTo(right_image_view.snp.bottom).offset(8)
        }
        
        root_view.addSubview(cancel_btn)
        root_view.addSubview(confirm_btn)
        
        cancel_btn.snp.remakeConstraints { (make) in
            make.bottom.equalToSuperview().offset(-8)
            make.width.equalTo(200)
            make.height.equalTo(44)
            make.centerX.equalToSuperview()
        }
        
        
        confirm_btn.snp.remakeConstraints { (make) in
            make.bottom.equalTo(cancel_btn.snp.top)
            make.width.equalTo(200)
            make.height.equalTo(44)
            make.centerX.equalToSuperview()
        }
        
    }
    
//    MARK: - Properties
    fileprivate lazy var root_view:UIView = {
       let control = UIView()
        control.backgroundColor = Color.white
        control.cornerRadius = 20
        control.borderColor = Color.init(hexString: "#979797")
        control.borderWidth = 1
        return control
    }()
    
    fileprivate lazy var cover_image_view:UIImageView = {
        let control = UIImageView()
        control.contentMode = UIView.ContentMode.scaleAspectFill
        control.cornerRadius = 45
        
        if let url = ST_BTUserInfoManager.shared.current_account_info?.userinfo?.avatar.compress_small_image(width: 90*2).url{
            
            control.pin_setImage(from: url, placeholderImage: ST_SwiftConst.shared.fetch_random_place_holder_image())
            
        }
        
        return control
    }()

    fileprivate lazy var cover_tips_image_view:UIImageView = {
        let control = UIImageView.init(image: ST_ImageUtils.imageName("avatar_change_tips_icon"))
        return control
    }()
    
    
    fileprivate lazy var titleLabel:UILabel = {
        let control = UILabel.init()
        let attrString = NSMutableAttributedString(string: "头像未通过审核")
        control.numberOfLines = 0
        let attr: [NSAttributedString.Key : Any] = [.font: UIFont.systemFont(ofSize: 18, weight: UIFont.Weight.medium),.foregroundColor: UIColor(red: 0.2, green: 0.2, blue: 0.2, alpha: 1)]
        attrString.addAttributes(attr, range: NSRange(location: 0, length: attrString.length))
        control.attributedText = attrString
        return control
    }()
    
    fileprivate lazy var content_label:UILabel = {
        let label = UILabel.init()
        
        let attrString = NSMutableAttributedString(string: "原因是")
        
        label.numberOfLines = 0
        
        let attr: [NSAttributedString.Key : Any] = [.font: UIFont.systemFont(ofSize: 14),.foregroundColor: UIColor(red: 0.38, green: 0.4, blue: 0.44, alpha: 1)]
        
        attrString.addAttributes(attr, range: NSRange(location: 0, length: attrString.length))
        
        

        let strSubAttr2: [NSMutableAttributedString.Key: Any] = [.font: UIFont.systemFont(ofSize: 14),.foregroundColor: UIColor(red: 1, green: 0.76, blue: 0.03,alpha:1.000000)]
        
        
        let attrString2 = NSMutableAttributedString(string: "疑似不是本人")
        
        attrString2.addAttributes(strSubAttr2, range: NSRange(location: 0, length: attrString2.length))
        
        let attrString3 = NSMutableAttributedString(string: "，请更换本人头\n像完成最后一步吧！")
        
        attrString3.addAttributes(attr, range: NSRange(location: 0, length: attrString3.length))
        
        let style = NSMutableParagraphStyle()
        style.alignment = NSTextAlignment.center
        style.lineSpacing = 3
        
        
        attrString.append(attrString2)
        
        attrString.append(attrString3)
        
        attrString.addAttributes([NSAttributedString.Key.paragraphStyle : style], range: NSRange(location: 0, length: attrString.length))
        
        label.attributedText = attrString
        
        return label
    }()
    
    
    
    
    
    
    lazy var center_image_view:UIImageView = {
        let control = UIImageView()
        control.contentMode = UIView.ContentMode.scaleAspectFill
        control.image = ST_ImageUtils.imageName("注册_img_非人物")
        //control.alpha = 0
        return control
    }()
    
    lazy var center_mistake_image_view:UIImageView = {
       let control = UIImageView()
        control.image = ST_ImageUtils.imageName("注册_icon_错误示范")
        //control.alpha = 0
        return control
    }()
    
    lazy var left_image_view:UIImageView = {
        let control = UIImageView()
        control.contentMode = UIView.ContentMode.scaleAspectFill
        control.image = ST_ImageUtils.imageName("注册_img_模糊不清")
        //control.alpha = 0
        return control
    }()
    
    lazy var left_mistake_image_view:UIImageView = {
       let control = UIImageView()
        control.image = ST_ImageUtils.imageName("注册_icon_错误示范")
        //control.alpha = 0
        return control
    }()
    
    lazy var right_image_view:UIImageView = {
        let control = UIImageView()
        control.contentMode = UIView.ContentMode.scaleAspectFill
        control.image = ST_ImageUtils.imageName("注册_img_多人合照")
        //control.alpha = 0
        return control
    }()
    
    lazy var right_mistake_image_view:UIImageView = {
       let control = UIImageView()
        control.image = ST_ImageUtils.imageName("注册_icon_错误示范")
        //control.alpha = 0
        return control
    }()
    
    lazy var center_label:UILabel = {
        let control = UILabel()
        control.text = "非人物照片"
        control.textAlignment = .center
        control.font = UIFont.systemFont(ofSize: 12, weight: UIFont.Weight.regular)
        control.textColor = Color.init(hex: 0x333333)
        //control.alpha = 0
        return control
    }()
    
    lazy var left_label:UILabel = {
        let control = UILabel()
        control.text = "模糊不清"
        control.font = UIFont.systemFont(ofSize: 12, weight: UIFont.Weight.regular)
        control.textColor = Color.init(hex: 0x333333)
        //control.alpha = 0
        return control
    }()
    
    
    lazy var right_label:UILabel = {
        let control = UILabel()
        control.text = "多人合拍"
        control.font = UIFont.systemFont(ofSize: 12, weight: UIFont.Weight.regular)
        control.textColor = Color.init(hex: 0x333333)
        //control.alpha = 0
        return control
    }()
    
    
    
    fileprivate lazy var confirm_btn:UIButton = {
            
        let control = UIButton.init(type: UIButton.ButtonType.custom)
        control.backgroundColor = Color.init(hexString: "#FEC207")
        control.cornerRadius = 44/2.0
        control.setTitleForAllStates("更换头像")
        control.titleLabel?.font = UIFont.systemFont(ofSize: 16, weight: UIFont.Weight.semibold)
        control.setTitleColorForAllStates(UIColor.white)
        control.addTarget(self, action: #selector(confirm_handle), for: UIControl.Event.touchUpInside)
        return control
    }()
    
    @objc fileprivate func confirm_handle(){
        
        goback_previous_controller(animated: false) {
            
            GlobalPresent(toController: ST_MyPhotoViewController())
            
        }
        
        
    }
    
    
    fileprivate lazy var cancel_btn:UIButton = {
            
        let control = UIButton.init(type: UIButton.ButtonType.custom)
        control.backgroundColor = .clear
        control.cornerRadius = 44/2.0
        control.titleLabel?.font = UIFont.systemFont(ofSize: 15, weight: UIFont.Weight.regular)
        control.setTitleForAllStates("稍后再说")
        control.setTitleColorForAllStates(UIColor.init(hexString: "#61666F")!)
        control.addTarget(self, action: #selector(cancel_handle), for: UIControl.Event.touchUpInside)
        return control
    }()
    
    @objc fileprivate func cancel_handle(){
        
        goback_previous_controller()
    }
}
